package com.fanrui.code.chess.mahjong.round;

import java.util.List;

import com.fanrui.code.chess.mahjong.AbstractMahjongTable;
import com.fanrui.code.chess.mahjong.Mahjong;
import com.fanrui.code.mahjong.util.MahjongCardUtil;
import com.fanrui.proto.cmd.Operation;
import com.google.gson.annotations.Expose;

/**
 * 麻将操作响应
 * @author Administrator
 *
 */
public class MahjongOperationResponse implements Comparable<MahjongOperationResponse>{
	@Expose
	private long operationId;
	@Expose
	private Operation type;
	@Expose
	private Mahjong card;
	@Expose
	private List<Mahjong> cards;
	@Expose
	private AbstractMahjongTable<?> table;
	public void setCard(com.fanrui.proto.cmd.Mahjong card) {
		this.card = MahjongCardUtil.getMahjong(card.getCid());
	}
	public void setCard(Mahjong card) {
		this.card = card;
	}
	public void setOperationId(long operationId) {
		this.operationId = operationId;
	}
	public void setType(Operation type) {
		this.type = type;
	}
	public void setTable(AbstractMahjongTable<?> table) {
		this.table = table;
	}
	public List<Mahjong> getCards() {
		return cards;
	}
	public void setCards(List<Mahjong> cards) {
		this.cards = cards;
	}
	public long getOperationId() {
		return operationId;
	}
	public Operation getType() {
		return type;
	}
	public Mahjong getCard() {
		return card;
	}
	public AbstractMahjongTable<?> getTable() {
		return table;
	}
	@Override
	public int compareTo(MahjongOperationResponse o) {
		int i=0,j=0;
		if(table != null) {
			i = table.getSeatNoByPlayerID(o.operationId);
			j = table.getSeatNoByPlayerID(operationId);
		}
		if(o.type.getNumber() > type.getNumber()){
			return 1;
		}
		if(o.type.getNumber() < type.getNumber()){
			return -1;
		}
		if(j == 0) {
			if(i == 2 || i == 3) {
				return 1;
			}
		}
		if(i == 0) {
			if(i == 2 || i == 3) {
				return -1;
			}
		}
		if(i <  j) {
			return 1;
		}
		if(i >  j) {
			return -1;
		}
		return 0;
	}
	
	public static MahjongOperationResponse  createTouchCardOperation(long playerId,com.fanrui.code.chess.mahjong.Mahjong card){
		MahjongOperationResponse response = new MahjongOperationResponse();
		response.setOperationId(playerId);
		response.setType(Operation.TOUCH);
		response.setCard(card);
		return response;
	}
	
	@Override
	public String toString() {
		return String.format("玩家%s响应%s操作 操作的牌%s",operationId,type,card);
	}
}
